using System.Web.Http;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Practices.Unity;
using PublishNews.Entities;
using PublishNews.Repositories;
using Unity.Mvc4;

namespace PublishNews
{
    public static class Bootstrapper
    {
        public static IUnityContainer Initialise()
        {
            var container = BuildUnityContainer();

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
            return container;
        }

        private static IUnityContainer BuildUnityContainer()
        {
            var container = new UnityContainer();

            // register all your components with the container here
            // it is NOT necessary to register your controllers

            // e.g. container.RegisterType<ITestService, TestService>();    
            RegisterTypes(container);

            return container;
        }

        public static void RegisterTypes(IUnityContainer container)
        {
            container.RegisterInstance(typeof(HttpConfiguration), GlobalConfiguration.Configuration);
            container.RegisterInstance<UserManager<User>>(new UserManager<User>(new UserStore<User>(new PublishNewsContext())));
            container.RegisterType<ICategoryRepository, CategoryRepository>();
            container.RegisterType<ILocationRepository, LocationRepository>();
            container.RegisterType<INewsRepository, NewsRepository>();
            container.RegisterType<IDistrictRepository, DistrictRepository>();
            container.RegisterType<IBannerRepository, BannerRepository>();

        }
    }
}